package com.fs.model;

import com.fs.util.FATUtil;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import lombok.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class File {

    private String fileName;//文件名
    private String type;// 类型
    private int diskNum;// 起始盘块号
    private String location; // 位置path
    private int length;// 占用盘块数
    private String space; // 占用空间
    private Date createTime;//创建时间

    private String content;// 内容
    private double size; // 大小
    private int flag;//读写权限，0可读，1可写

    private boolean isOpen;//打开标志，防止重复打开
    private Folder parent;//父文件夹


    private transient StringProperty fileNameP = new SimpleStringProperty();
    private transient StringProperty flagP = new SimpleStringProperty();
    private transient StringProperty diskNumP = new SimpleStringProperty();
    private transient StringProperty locationP = new SimpleStringProperty();
    private transient StringProperty lengthP = new SimpleStringProperty();

    public File(String fileName, String location, int diskNum, Folder parent) {
        this.fileName = fileName;
        this.type = FATUtil.FILE;
        this.diskNum = diskNum;
        this.length = 1;
        this.content = "";

        this.location = location;
        this.size = FATUtil.getSize(content.length());
        this.space = size + "KB";
        this.createTime = new Date();//记录创建时间;

        this.parent = parent;


    }
    public boolean isOpened() {
        return isOpen;
    }
    public void setOpened(boolean isOpen) {
        this.isOpen = isOpen;
    }
    //UI获取property
    public StringProperty fileNamePProperty() {
        return fileNameP;
    }
    public boolean hasParent() {
        return (parent == null) ? false : true;
    }
    public String getCreateTime() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日  HH:mm:ss");
        return format.format(createTime);
    }
}
